#include<bits/stdc++.h>
using namespace std;
int n;
int a[200010];
int k[1000010];
int c[200010];
int T;
vector<int> v;
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>T;
	while(T--){
		cin>>n;
		memset(k,0,sizeof k);
		memset(c,0,sizeof c);
		v.clear();
		for(int i=1;i<=n;i++){
			cin>>a[i];
			k[a[i]]++;
			if(k[a[i]]==1)v.push_back(a[i]);
		}
		int ans=0;
		for(int i=0;i<v.size();i++){
			ans+=(k[v[i]]-1)*v[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}
